package com.yunding.house.service.impl;


import com.yunding.house.mapper.UserMapper;
import com.yunding.house.pojo.User;
import com.yunding.house.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户登录账户表 服务实现类
 * </p>
 *
 * @author linyang
 * @since 2019-08-15
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 获取所有用户
     * @return
     */
    public List<User> findAll() {
        return userMapper.selectList(null);
    }

    /**
     * 保存
     * @param user
     * @return
     */
    public boolean save(User user) {
        System.out.println("user:="+user);
        int n = userMapper.insert(user);
        if(n>0){
            return true;
        }
        return false;
    }

    /**
     * 保存
     * @param user
     * @return
     */
    @Override
    public boolean update(User user) {
        return userMapper.updateById(user)>=1? true : false;
    }

    /**
     * 保存
     * @param invitationCode
     * @return
     */
    @Override
    public User selectByinvcode(String invitationCode) {
        return userMapper.selectByinvcode(invitationCode);
    }

    /**
     * openid查找user
     * @param openid
     * @return
     */
    @Override
    public User selectByopenid(String openid) {
        return userMapper.selectByopenid(openid);
    }

    /**
     * username查找user
     *
     * @param username
     * @return
     */
    @Override
    public User selectByusername(String username) {
        return userMapper.selectByusername(username);
    }


}
